void a(vector<TH1 *> &v, TObject *h){ v.push_back((TH1 *)h); }

void cc(int id, const string &t, string &cmd){
  char ii[64]; sprintf(ii, "%d", id); string i = ii;
  cmd = t+".ang()>>h"+ii+"(500, -3., 3.)";
} // end cc
void cc2(int id, const string &t, string &cmd){
  char ii[64]; sprintf(ii, "%d", id); string i = ii;
  cmd = t+".angx():"+t+".angy()>>h"+ii+
    "(500, -3., 3., 500, -3., 3.)";
} // end cc2

void k(){
  TFile *f = new TFile(getenv("TMP1"), "UPDATE");
  TTree *etf = (TTree *)f->Get("etf");
  vector<TH1 *> v;
  string c;

  // --------------------- 14. Track Angle Distribution ----------------------- //
  cc(1, "preTaTrackerX", c); etf->Draw(c.c_str()); a(v,f->Get("h1"));
  cc(2, "preTaTrackerY", c); etf->Draw(c.c_str()); a(v,f->Get("h2"));
  cc2(3, "preTaTracker3D", c); etf->Draw(c.c_str()); a(v,f->Get("h3"));
  cc(4, "postTaTrackerX", c); etf->Draw(c.c_str()); a(v,f->Get("h4"));
  cc(5, "postTaTrackerY", c); etf->Draw(c.c_str()); a(v,f->Get("h5"));
  cc2(6, "postTaTracker3D", c); etf->Draw(c.c_str()); a(v,f->Get("h6"));
  // cc(7, "ta4TrackerX", c); etf->Draw(c.c_str()); a(v,f->Get("h7"));
  // cc(8, "ta4TrackerY", c); etf->Draw(c.c_str()); a(v,f->Get("h8"));
  // cc2(9, "ta4Tracker3D", c); etf->Draw(c.c_str()); a(v,f->Get("h9"));
  cout << "etf->Draw(\"" << c << "\")" << endl;


  TCanvas *c1 = new TCanvas("c", "Track Angle Distribution", 1680, 1050);
  c1->Divide(3,2);
  for(int i = 0; i < 6; i++){
    c1->cd(i+1); v[i]->Draw("colz");
    if(!((i+1)%3)){
      v[i]->GetXaxis()->SetTitle("AngleX [degree]");
      v[i]->GetYaxis()->SetTitle("AngleY [degree]");
    } // end if
    else v[i]->GetXaxis()->SetTitle("Angle [degree]");
  } // end for
  c1->Print("k.pdf");
} // end vis
